package a02;

import util.Pair;

public class GameMaster {

    private int version = 0;
    private Pair<Byte, Byte> pos;
    private byte playerID;
    private byte hostID = -1;
    private byte clientID = -1;

    private int versionHost = 0;
    private int versionClient = 0;

    public GameMaster() {

    }

    public int getVersion() {
	return this.version;
    }

    public void setMouseClick(byte c, byte r, byte playerID) {
	this.setPos(new Pair<Byte, Byte>(c, r));
	this.setPlayerID(playerID);
	incrementVersion();
	System.out.println(version);
    }

    public boolean isUpdated(int version) {
	return this.version > version;
    }

    public Pair<Byte, Byte> getPos() {
	return pos;
    }

    public void setPos(Pair<Byte, Byte> pos) {
	this.pos = pos;
    }

    public byte getPlayerID() {
	return playerID;
    }

    public void setPlayerID(byte playerID) {
	this.playerID = playerID;
    }

    public void incrementVersion() {
	this.version++;
    }

    public int getVersionHost() {
	return versionHost;
    }

    public void setVersion(byte playerID, int version) {
	if (playerID == getHostID()) {
	    this.versionHost = version;
	} else if (playerID == getClientID()) {
	    this.versionClient = version;
	}
    }

    public int getVersionClient() {
	return versionClient;
    }

    public byte getHostID() {
	return hostID;
    }

    public void setHostID(byte hostID) {
	this.hostID = hostID;
    }

    public byte getClientID() {
	return clientID;
    }

    public void setClientID(byte clientID) {
	this.clientID = clientID;
    }

    public int getVersion(byte playerID) {
	int result = 0;
	if (playerID == getHostID())
	    result = getVersionHost();
	if (playerID == getClientID())
	    result = getVersionClient();
	return result;
    }

}
